package com.xiaoma.tpo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaoma.tpo.dao.UserDeviceDao;
import com.xiaoma.tpo.domain.UserDevice;

@Service
public class UserDeviceService {

    @Autowired
    private UserDeviceDao userDeviceDao;
    
    public void save(UserDevice userDevice) {
        userDeviceDao.insert(userDevice);
    }
    
    public List<UserDevice> findByUserId(int userId) {
        UserDevice entity = new UserDevice();
        entity.setUserId(userId);
        List<UserDevice> userDevices = userDeviceDao.findByColumns(entity);
        return userDevices;
    }
    
    public UserDevice findByUserIdAndDevice(int userId, String device) {
        UserDevice entity = new UserDevice();
        entity.setUserId(userId);
        entity.setDevice(device);
        List<UserDevice> userDevices = userDeviceDao.findByColumns(entity);
        return userDevices.size() > 0 ? userDevices.get(0) : null;
    }
    
}
